﻿using System;

public class Employee
{
    private int id;
    private string name;
    private int age;
    private string department;
    private string position;
    private decimal salary;
    private DateTime hireDate;

    public Employee()
    {
        this.id = 0;
        this.name = "未知";
        this.age = 0;
        this.department = "未分配";
        this.position = "未指定";
        this.salary = 0;
        this.hireDate = DateTime.MinValue;
    }

    public Employee(int id, string name, int age, string department, string position, decimal salary, DateTime hireDate)
    {
        this.id = id;
        this.name = name;
        this.age = age;
        this.department = department;
        this.position = position;
        this.salary = salary;
        this.hireDate = hireDate;
    }

    public int Id
    {
        get { return id; }
        set { id = value; }
    }

    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    public int Age
    {
        get { return age; }
        set { age = value; }
    }

    public string Department
    {
        get { return department; }
        set { department = value; }
    }

    public string Position
    {
        get { return position; }
        set { position = value; }
    }

    public decimal Salary
    {
        get { return salary; }
        set { salary = value; }
    }

    public DateTime HireDate
    {
        get { return hireDate; }
        set { hireDate = value; }
    }

    public int GetYearsOfService()
    {
        if (hireDate == DateTime.MinValue)
            return 0;

        DateTime today = DateTime.Today;
        int years = today.Year - hireDate.Year;

        if (hireDate.Date > today.AddYears(-years))
            years--;

        return years;
    }

    public void DisplayInfo()
    {
        Console.WriteLine("===== 员工信息 =====");
        Console.WriteLine($"员工ID: {id}");
        Console.WriteLine($"姓名: {name}");
        Console.WriteLine($"年龄: {age}");
        Console.WriteLine($"部门: {department}");
        Console.WriteLine($"职位: {position}");
        Console.WriteLine($"薪资: {salary:C}");

        if (hireDate != DateTime.MinValue)
        {
            Console.WriteLine($"入职日期: {hireDate:yyyy-MM-dd}");
            Console.WriteLine($"工龄: {GetYearsOfService()} 年");
        }
        else
        {
            Console.WriteLine("入职日期: 未设置");
        }

        Console.WriteLine("====================");
    }
}

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("员工管理系统");
        Console.WriteLine("==============");

        Employee emp1 = new Employee();
        Console.WriteLine("\n使用无参构造函数创建的员工:");
        emp1.DisplayInfo();

        Employee emp2 = new Employee(1001, "张三", 28, "技术部", "软件工程师", 15000m, new DateTime(2019, 5, 10));
        Console.WriteLine("\n使用有参构造函数创建的员工:");
        emp2.DisplayInfo();

        Employee emp3 = new Employee();
        emp3.Id = 1002;
        emp3.Name = "李四";
        emp3.Age = 32;
        emp3.Department = "市场部";
        emp3.Position = "市场经理";
        emp3.Salary = 20000m;
        emp3.HireDate = new DateTime(2017, 8, 15);

        Console.WriteLine("\n使用属性设置的员工:");
        emp3.DisplayInfo();

        Console.WriteLine("\n修改员工信息...");
        emp2.Position = "高级软件工程师";
        emp2.Salary = 18000m;

        Console.WriteLine("\n修改后的员工信息:");
        emp2.DisplayInfo();

        Console.WriteLine("\n员工列表:");
        Employee[] employees = new Employee[3];
        employees[0] = emp1;
        employees[1] = emp2;
        employees[2] = emp3;

        foreach (Employee emp in employees)
        {
            emp.DisplayInfo();
        }

        Console.WriteLine("\n按任意键退出...");
        Console.ReadKey();
    }
}